home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-10-21 | 20.0 KB | 566 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // File: U3DDrawing.h
- //
- // Contains: Headers for 3D drawing routines.
- //
- // Written by: Jamie Osborne, Robin Mair, Faulkner White, Henri Lamiraux
- // Adapted for 3.1.1 by Jeroen Schalk
- //
- // Copyright: © 1992-1994 by Apple Computer, Inc.
- //----------------------------------------------------------------------------------------
-
- #ifndef __U3DDRAWING__
- #define __U3DDRAWING__
-
- #ifndef __UCONTROL__
- #include <UControl.h>
- #endif
-
- #ifndef __ICONS__
- #include "Icons.h"
- #endif
-
- //----------------------------------------------------------------------------------------
-
- // 8Bit gray shade constants
- const short kRGB8BitGray1 = 61166; // Light gray
- const short kRGB8BitGray2 = 56797; // Slightly darker gray
- const short kRGB8BitGray3 = 52428; // Slightly darker gray
- const short kRGB8BitGray4 = 48059; // Slightly darker gray
- const short kRGB8BitGray5 = 43690; // Slightly darker gray
- const short kRGB8BitGray6 = 34952; // Slightly darker gray
- const short kRGB8BitGray7 = 30583; // Slightly darker gray
- const short kRGB8BitGray8 = 21845; // Slightly darker gray
- const short kRGB8BitGray9 = 17476; // Slightly darker gray
- const short kRGB8BitGray10 = 8738; // Slightly darker gray
- const short kRGB8BitGray11 = 4369; // Dark gray
-
- // 4Bit gray shade constants
- const short kRGB4BitGray1 = 49152; // Light gray
- const short kRGB4BitGray2 = 32768; // Medium gray
- const short kRGB4BitGray3 = 8192; // Dark gray
-
- // Some constants for drawing grays
- const CRGBColor kLightGray = CRGBColor(kRGB8BitGray1, kRGB8BitGray1, kRGB8BitGray1);
- const CRGBColor kLightGray2 = CRGBColor(kRGB8BitGray2, kRGB8BitGray2, kRGB8BitGray2);
- const CRGBColor kLightGray4 = CRGBColor(kRGB8BitGray4, kRGB8BitGray4, kRGB8BitGray4);
- const CRGBColor kMediumLightGray = CRGBColor(kRGB8BitGray5, kRGB8BitGray5, kRGB8BitGray5);
- const CRGBColor kMediumGray = CRGBColor(kRGB8BitGray6, kRGB8BitGray6, kRGB8BitGray6);
-
- //----------------------------------------------------------------------------------------
- // InitU3DDrawing
- // This function initializes the 3D library. You must call this function in your
- // initialization routine.
- //----------------------------------------------------------------------------------------
-
- void InitU3DDrawing();
-
- //----------------------------------------------------------------------------------------
- // ••• 3D Utility Classes •••
- //----------------------------------------------------------------------------------------
-
- //----------------------------------------------------------------------------------------
- // CGraphicsState
- // A stack-based object that remembers the graphics state (BW and color)
- // and restores it when it passes out of scope
- //----------------------------------------------------------------------------------------
-
- class CGraphicsState
- {
- private:
- CRGBColor fSaveForeColor;
- CRGBColor fSaveBackColor;
- PenState fSavePenState;
- TextStyle fSaveTextStyle;
-
- public:
- CGraphicsState();
- ~CGraphicsState();
-
- void Save();
- void Restore();
-
- }; // CGraphicsState
-
- //----------------------------------------------------------------------------------------
- // CDrawPerDevice
- // A stack-based object that allows drawing in different pixel depths across
- // different monitors
- // If you're not using C++, just use DeviceLoop. It's faster than CDrawPerDevice
- // However, if you are using C++, CDrawPerDevice can save you some headaches
- // having to deal with static drawing routines and the like
- //----------------------------------------------------------------------------------------
-
- class CDrawPerDevice
- {
- private:
- CRect fGlobalArea;
- GDHandle fGDHandle;
- RgnHandle fSaveClip;
- FocusRec fFocus;
- Boolean fDoneOldQD;
-
- public:
- CDrawPerDevice();
- CDrawPerDevice(const CRect& area);
- ~CDrawPerDevice();
-
- void SetDrawingArea(const CRect& area);
- Boolean NextDevice(short& pixelSize);
-
- }; // CDrawPerDevice
-
- //----------------------------------------------------------------------------------------
- // CPenNormal
- // Sets the fore and back color to black and white and calls PenNormal
- //----------------------------------------------------------------------------------------
-
- void CPenNormal();
-
- //----------------------------------------------------------------------------------------
- // ••• 3D TView Adorners •••
- //----------------------------------------------------------------------------------------
-
- const IDType kGrayBackgroundAdorner = 'grba';
- const IDType kWhiteBackgroundAdorner = 'whba';
- const IDType k3DGrayBackgroundAdorner = '3dgb';
- const IDType k3DLineTopAdorner = '3dlt';
- const IDType k3DLineBottomAdorner = '3dlb';
- const IDType k3DLineLeftAdorner = '3dll';
- const IDType k3DLineRightAdorner = '3dlr';
- const IDType k3DFrameAdorner = '3dfr';
-
- //----------------------------------------------------------------------------------------
- // TWhiteBackgroundAdorner
- //----------------------------------------------------------------------------------------
-
- class TWhiteBackgroundAdorner : public TAdorner
- {
- DeclareClass(TWhiteBackgroundAdorner);
-
- public:
- TWhiteBackgroundAdorner();
- virtual void IWhiteBackgroundAdorner(Boolean freeOnDeletion);
- virtual void Draw(TView* itsView, const VRect& area);
- };
-
- //----------------------------------------------------------------------------------------
- // TGrayBackgroundAdorner
- //----------------------------------------------------------------------------------------
-
- class TGrayBackgroundAdorner : public TAdorner
- {
- DeclareClass(TGrayBackgroundAdorner);
-
- public:
- TGrayBackgroundAdorner();
- virtual void IGrayBackgroundAdorner(Boolean freeOnDeletion);
- virtual void Draw(TView* itsView, const VRect& area);
- };
-
- //----------------------------------------------------------------------------------------
- // T3DGrayBackgroundAdorner
- //----------------------------------------------------------------------------------------
-
- class T3DGrayBackgroundAdorner : public TGrayBackgroundAdorner
- {
- DeclareClass(T3DGrayBackgroundAdorner);
-
- public:
- T3DGrayBackgroundAdorner();
- virtual void I3DGrayBackgroundAdorner(Boolean freeOnDeletion);
- virtual void Draw(TView* itsView, const VRect& area);
- };
-
- //----------------------------------------------------------------------------------------
- // T3DLineTopAdorner
- //----------------------------------------------------------------------------------------
-
- class T3DLineTopAdorner : public TAdorner
- {
- DeclareClass(T3DLineTopAdorner);
-
- public:
- T3DLineTopAdorner();
- virtual void I3DLineTopAdorner(Boolean freeOnDeletion);
- virtual void Draw(TView* itsView, const VRect& area);
- };
-
- //----------------------------------------------------------------------------------------
- // T3DLineBottomAdorner
- //----------------------------------------------------------------------------------------
-
- class T3DLineBottomAdorner : public TAdorner
- {
- DeclareClass(T3DLineBottomAdorner);
-
- public:
- T3DLineBottomAdorner();
- virtual void I3DLineBottomAdorner(Boolean freeOnDeletion);
- virtual void Draw(TView* itsView, const VRect& area);
- };
-
- //----------------------------------------------------------------------------------------
- // T3DLineLeftAdorner
- //----------------------------------------------------------------------------------------
-
- class T3DLineLeftAdorner : public TAdorner
- {
- DeclareClass(T3DLineLeftAdorner);
-
- public:
- T3DLineLeftAdorner();
- virtual void I3DLineLeftAdorner(Boolean freeOnDeletion);
- virtual void Draw(TView* itsView, const VRect& area);
- };
-
- //----------------------------------------------------------------------------------------
- // T3DLineRightAdorner
- //----------------------------------------------------------------------------------------
-
- class T3DLineRightAdorner : public TAdorner
- {
- DeclareClass(T3DLineRightAdorner);
-
- public:
- T3DLineRightAdorner();
- virtual void I3DLineRightAdorner(Boolean freeOnDeletion);
- virtual void Draw(TView* itsView, const VRect& area);
- };
-
- //----------------------------------------------------------------------------------------
- // T3DFrameAdorner
- //----------------------------------------------------------------------------------------
-
- class T3DFrameAdorner : public TAdorner
- {
- DeclareClass(T3DFrameAdorner);
-
- public:
- T3DFrameAdorner();
- virtual void I3DFrameAdorner(Boolean freeOnDeletion);
- virtual void Draw(TView* itsView, const VRect& area);
- };
-
- //----------------------------------------------------------------------------------------
- // ••• TControl classes and auxiliary adorners •••
- //----------------------------------------------------------------------------------------
-
- //----------------------------------------------------------------------------------------
- // T3DCheckBox
- // A 3D version of the check box control. This class circumvents the control CDEF
- //----------------------------------------------------------------------------------------
-
- class T3DCheckBox : public TCheckBox
- {
- DeclareClass(T3DCheckBox);
-
- protected:
- VRect fDrawBox;
- CRGBColor fForeColor;
- CRGBColor fBackColor;
-
- public:
- T3DCheckBox() {this->Initialize();}
- virtual void Initialize(void);
- virtual void DoPostCreate(TDocument *itsDocument);
- virtual void I3DCheckBox (TView* itsSuperView, const VPoint& itsLocation,
- const VPoint& itsSize, SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet, const CStr255& itsLabel,
- Boolean isTurnedOn);
- virtual TObject* Clone();
- virtual void Free();
-
- virtual void DoMouseCommand(VPoint& theMouse,TToolboxEvent*,CPoint);
- virtual void TrackMouse(TrackPhase aTrackPhase, VPoint& anchorPoint,
- VPoint& previousPoint, VPoint& nextPoint, Boolean);
-
- virtual void Draw(const VRect& area);
- virtual void DimState(Boolean state,Boolean redraw);
- virtual void SetLongVal(VCoordinate itsVal, Boolean redraw);
- virtual void HiliteState(Boolean state,Boolean redraw);
- virtual void Hilite();
- virtual void Dim();
- inline void SetBackColor(CRGBColor newColor) {fBackColor = newColor;}
- virtual void InstallColor(const CRGBColor& theColor, Boolean redraw);
-
- private:
- virtual void DrawBoxText(const CStr255& s, const CRect& box, Boolean preferOutline);
- virtual void DrawBox();
- virtual void DrawCheck();
-
- }; // T3DCheckBox
-
- //----------------------------------------------------------------------------------------
- // T3DRadio
- // A 3D version of the radio button. This class circumvents the control CDEF
- //----------------------------------------------------------------------------------------
-
- class T3DRadio : public TRadio
- {
- DeclareClass(T3DRadio);
-
- protected:
- VRect fDrawBox;
- CRGBColor fForeColor;
- CRGBColor fBackColor;
-
- public:
- T3DRadio() {this->Initialize();}
- virtual void Initialize(void);
- virtual void DoPostCreate(TDocument *itsDocument);
- virtual void I3DRadio (TView* itsSuperView, const VPoint& itsLocation,
- const VPoint& itsSize, SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet, const CStr255& itsLabel,
- Boolean isTurnedOn);
- virtual TObject* Clone();
- virtual void Free();
-
- virtual void DoMouseCommand(VPoint& theMouse,TToolboxEvent*,CPoint);
- virtual void TrackMouse(TrackPhase aTrackPhase, VPoint& anchorPoint,
- VPoint& previousPoint, VPoint& nextPoint, Boolean);
-
- virtual void Draw(const VRect& area);
- virtual void DimState(Boolean state,Boolean redraw);
- virtual void SetLongVal(VCoordinate itsVal, Boolean redraw);
- virtual void HiliteState(Boolean state,Boolean redraw);
- virtual void Hilite();
- virtual void Dim();
- inline void SetBackColor(CRGBColor newColor) {fBackColor = newColor;}
- virtual void InstallColor(const CRGBColor& theColor, Boolean redraw);
-
- private:
- virtual void DrawBoxText(const CStr255& s, const CRect& box, Boolean preferOutline);
- virtual void DrawBox();
- virtual void DrawCheck();
- };
-
- //----------------------------------------------------------------------------------------
- // T3DButton
- // A 3D version of the push button. This class circumvents the control CDEF
- //----------------------------------------------------------------------------------------
-
- class T3DButton : public TButton
- {
- DeclareClass(T3DButton);
-
- protected:
- TAdorner* f3DAdorner;
- CRGBColor fHilitedTextColor;
-
- public:
- T3DButton() {this->Initialize();}
- virtual void Initialize(void);
- virtual void DoPostCreate(TDocument *itsDocument);
- virtual void I3DButton(TView* itsSuperView, const VPoint& itsLocation,
- const VPoint& itsSize, SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet, const CStr255& itsLabel);
- virtual TObject* Clone();
- virtual void Free();
- virtual void CreateButtonAdorner();
-
- virtual void DoMouseCommand(VPoint& theMouse,TToolboxEvent*,CPoint);
- virtual void TrackMouse(TrackPhase aTrackPhase, VPoint& anchorPoint, VPoint& previousPoint,
- VPoint& nextPoint, Boolean);
-
- virtual void DimState(Boolean state,Boolean redraw);
- virtual void HiliteState(Boolean state,Boolean redraw);
- virtual void Draw(const VRect& area);
- virtual void Hilite();
- virtual void Dim();
- inline void SetHilitedTextColor(const CRGBColor& color) { fHilitedTextColor = color; }
-
- private:
- virtual void DrawBoxText(const CStr255& s, const CRect& box, Boolean preferOutline );
-
- }; // T3DButton
-
- //----------------------------------------------------------------------------------------
- // T3DTextButtonAdorner
- // Adorner used by the T3DButton class for 3D drawing.
- //----------------------------------------------------------------------------------------
-
- // Round Rect Oval Constants
- const short kOvalWidth = 10;
- const short kOvalHeight = 10;
-
- const IDType k3DTextButtonAdorner= '3dtb';
-
- class T3DTextButtonAdorner : public TAdorner
- {
- DeclareClass(T3DTextButtonAdorner);
-
- public:
- T3DTextButtonAdorner() {};
- virtual void I3DTextButtonAdorner(Boolean freeOnDeletion);
- virtual void Draw(TView* itsView, const VRect& area);
-
- private:
- virtual void Draw8Bit(const CRect& rect, Boolean hilite );
- virtual void Draw4Bit(const CRect& rect, Boolean hilite );
- virtual void Draw1Bit(const CRect& rect, Boolean hilite );
- virtual void Frame(const CRect& rect);
- virtual void TopLeftCorner(const CRect& rect, const CRGBColor light,
- const CRGBColor dark, Boolean hilite );
- virtual void BotLeftCorner(const CRect& rect, const CRGBColor light,
- const CRGBColor dark, Boolean hilite );
- virtual void TopRightCorner(const CRect& rect, const CRGBColor light,
- const CRGBColor dark, Boolean hilite );
- virtual void BotRightCorner(const CRect& rect, const CRGBColor light,
- const CRGBColor dark, Boolean hilite );
-
- }; // T3DTextButtonAdorner
-
- //----------------------------------------------------------------------------------------
- // ••• 3DIconButton class and auxiliary adorner •••
- //----------------------------------------------------------------------------------------
-
- //----------------------------------------------------------------------------------------
- // TYPES
- //----------------------------------------------------------------------------------------
-
- typedef short ButtonMode; // Used to store the mode for Icon Buttons
-
- //----------------------------------------------------------------------------------------
- // CONSTANTS
- //----------------------------------------------------------------------------------------
-
- const IDType k3DIconAdorner = '3dia'; // IDType for our adorner
- const Boolean kButtonOn = true; // State button on
- const Boolean kButtonOff = false; // State button off
- const ButtonMode kButtonMode = 1; // Normal button Mode for state buttons
- const ButtonMode kSwitchMode = 2; // Toggle Mode for state buttons - default
- const ButtonMode kRadioMode = 3; // Exclusivity Mode for state buttons
-
- //----------------------------------------------------------------------------------------
- // T3DIconAdorner
- // Adorner used by the T3DIconButton class for 3D drawing.
- //----------------------------------------------------------------------------------------
-
- class T3DIconAdorner : public TAdorner
- {
- DeclareClass(T3DIconAdorner);
-
- public:
- T3DIconAdorner() {};
- virtual void I3DIconAdorner(Boolean freeOnDeletion);
- virtual void Draw(TView* itsView, const VRect& area);
-
- private:
- virtual void Draw8Bit(const CRect& rect, Boolean hilite);
- virtual void Draw4Bit(const CRect& rect, Boolean hilite);
- virtual void Draw1Bit(const CRect& rect, Boolean hilite);
- virtual void Frame(const CRect& rect);
- virtual void TopLeftSide(const CRect& rect);
- virtual void BotRightSide(const CRect& rect);
- virtual void TopLeftCorner(const CRect& rect, const CRGBColor light,
- const CRGBColor dark );
- virtual void BotLeftCorner(const CRect& rect, const CRGBColor light,
- const CRGBColor dark );
- virtual void TopRightCorner(const CRect& rect, const CRGBColor light,
- const CRGBColor dark );
- virtual void BotRightCorner(const CRect& rect, const CRGBColor light,
- const CRGBColor dark, Boolean hilite );
-
- }; // T3DIconAdorner
-
- //----------------------------------------------------------------------------------------
- // TIconSuite
- // Base class for the T3DIconButton. This class draws icon suites (icl#).
- //----------------------------------------------------------------------------------------
-
- const EventNumber mIconSuiteHit = 1100; // Hit in an Icon Suite
-
- class TIconSuite : public TControl
- {
- DeclareClass(TIconSuite);
-
- private:
-
- ResNumber fIconSuiteRsrcID; // Resource ID for the family of icons
- IconAlignmentType fAlignment; // Type of alignment we would like
- Handle fDataHandle; // Data handle for the icon family
- IconSelectorValue fSelectorValue;
-
- public:
- TIconSuite() {this->Initialize();}
- virtual void Initialize ();
- virtual void IIconSuite (TView* itsSuperView, const VPoint& itsLocation,
- const VPoint& itsSize, SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet, ResNumber itsRsrcID,
- IconAlignmentType alignment, IconSelectorValue selectorValue);
- virtual void DoPostCreate(TDocument *itsDocument);
-
- virtual TObject* Clone();
- virtual void Free();
- virtual void ReleaseIconSuite();
-
- virtual void GetIconRect(VRect& theRect);
- virtual void SetIconSuiteRsrcID(short itsRsrcID, IconSelectorValue selectorValue,
- Boolean redraw );
- virtual void SetIconSuite(Handle theSuite, Boolean redraw );
- virtual void SetAlignment(IconAlignmentType newAlignment, Boolean redraw );
-
- virtual void Draw(const VRect& area);
- virtual void Dim();
- virtual void Hilite();
-
- private:
- virtual void DoPlotIconSuite(IconTransformType transform);
-
- }; // TIconSuite
-
- //----------------------------------------------------------------------------------------
- // T3DIconButton
- // Implementation of 3d Icon button in color where available.
- //----------------------------------------------------------------------------------------
- const EventNumber mIconButtonHit = 1102; // Hit in an Icon Suite
-
-
- class T3DIconButton : public TIconSuite
- {
- DeclareClass(T3DIconButton);
-
- protected:
- TAdorner* f3DIconAdorner; // Reference to the adorner that does
- ButtonMode fMode; // What mode is this button operating under the initial
- // possibilities are : kRadioMode
- // kSwitchMode
- // kButtonMode
- Boolean fState; // Used to maintain the state of the button during tracking
-
- private:
- short fIconSize; // Either 12, 16 or 32
-
- public:
-
- T3DIconButton() {this->Initialize();};
- virtual void Initialize(void);
- virtual void I3DIconButton(TView* itsSuperView, const VPoint& itsLocation,
- const VPoint& itsSize, SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet, short iconSize,
- ResNumber itsRsrcID, ButtonMode mode,
- Boolean state );
- virtual void DoPostCreate(TDocument *itsDocument);
- virtual void CreateButtonAdorner ();
-
- virtual void GetIconRect(VRect& theRect);
- virtual void SetIconRsrcID(short itsRsrcID, Boolean redraw );
- virtual void SetMode(ButtonMode newMode);
- virtual ButtonMode GetMode();
- virtual Boolean IsSelected();
- virtual void TrackMouse(TrackPhase aTrackPhase,VPoint& ,
- VPoint& , VPoint& nextPoint,Boolean );
- virtual void Hilite();
- virtual void Dim();
-
- private:
- virtual short GetIconSize(const VPoint& viewSize);
- virtual void SetIconSuiteRsrcID(short itsRsrcID, IconSelectorValue selectorValue,
- Boolean redraw );
- virtual void SetIconSuite(Handle theSuite, Boolean redraw);
-
- }; // T3DIconButton
-
-
- #endif __U3DDRAWING__